<template>
  <div class="right-side">
    <div class="ranking">
      <h3>{{ title }}</h3>
      <ul>
        <li v-for="(item, index) in dataList" :key="index" class="ranking-item" @click="handleItemClick(item)">
          <span :class="getRankClass(index)">{{ index + 1 }}</span>
          <span>{{ item.name }}</span>
          <span style="padding-left: 10px; font-weight:normal; font-size:12px">{{ item.score }}</span>
        </li>
      </ul>
    </div>


  </div>
</template>

<script>
  export default {
    props: {
      title: {
        type: String,
        required: true
      },
      dataList: {
        type: Array,
        default: () => []
      }
    },
    methods: {
      handleItemClick(item) {
        // 发射一个自定义事件，并传递 item 数据
        this.$emit('item-click', item);
      },
      getRankClass(index) {
        if (index === 0) return 'rank-1';
        if (index === 1) return 'rank-2';
        if (index === 2) return 'rank-3';
        return 'rank-other';
      },
    },
  };
</script>

<style scoped>
  .right-side {
    width: 300px;
    padding: 0 0px;
    background-color: rgba(255, 255, 255, 0);
  }

  .ranking {
    padding: 20px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  }

  .ranking h3 {
    margin-top: 0;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--main-color);
    /* Use your main color variable */
    text-align: left;
  }

  .ranking ul {
    list-style-type: none;
    padding: 0;
    margin: 0;
  }

  .ranking-item {
    cursor: pointer;
    /* 添加指针光标，表示可点击 */
    transition: background-color 0.3s ease;
    /* 添加过渡效果 */

    margin-bottom: 12px;
    /* Adjust margin bottom */
    padding: 12px 20px;
    /* Adjust padding */
    background-color: #f9f9f9;
    border-radius: 6px;
    display: flex;
    justify-content: left;
    align-items: center;
    font-size: 16px;
    color: var(--text-color);
    /* Use your text color variable */
  }

  .ranking-item:hover {
    background-color: #e0e0e0;
    /* 悬停时的背景色 */
  }

  .ranking-item span {
    font-weight: bold;
    /* margin-right: 10px; */
    padding-right: 20px;
  }


  .rank-1 {
    color: gold;
    /* 第一名 */
  }

  .rank-2 {
    color: silver;
    /* 第二名 */
  }

  .rank-3 {
    color: bronze;
    /* 第三名 */
  }

  .rank-other {
    color: gray;
    /* 其他名次 */
  }
</style>
